import pymysql

import sys

tbl =  sys.argv[2]

conn = pymysql.connect(host='127.0.0.1', port=3306, user='social', passwd='Bytwitter#123', db='twitter', charset='utf8mb4')
curr = conn.cursor()

sql = f'''INSERT INTO {tbl} (crawler_time, crawler_time_stamp, screen_name, user_at_name, user_id, is_v, tx_url, pub_time, pub_time_stamp, url, tweet_id, tweet_content, reply_cnt, retweets_cnt, like_cnt, is_retweet, r_user_screen_name, r_user_at_name, r_user_id, r_url, r_tweet_id, r_tweet_content,  r_tx_url, r_is_v, r_source, r_lang, r_pub_time, r_reply_cnt, r_retweets_cnt, r_like_cnt, source, lang) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'''

with open(sys.argv[1], encoding='utf8') as fp:
    for i, line in enumerate(fp):
        t = line.strip().split('\t')
        curr.execute(sql, tuple(t[1:]))

        if i % 1000 == 999:
            conn.commit()
            print(i)

